<template>
    <div>
        <!-- 选择机构弹窗 -->
		<el-dialog
            :title="title"
            width="50%"
            top="5vh"
            :visible.sync="visibleDeptSelect"
        >
			<dept-tree      
                :showCheckbox="showCheckbox"
                :defaultExpandAll="defaultExpandAll" 
                :multiple="multiple"
                :branchId="branchId"
                :checkedKeys="checkedKeys"
                @check-change="checkChange"
            >
			</dept-tree>
			<span slot="footer" class="dialog-footer">
				<el-button size="small" @click="cancel">取 消</el-button>
				<el-button size="small" type="primary" @click="submit">确 定</el-button>
			</span>
        </el-dialog>
    </div>
</template>

<script>
 

export default {
    
    components: {   
	},

    props: ['isSingle','title', 'value','branchId','visible','nodeKey','showCount','showRoot','countTips','showFilter','rootKey','multiple','checkedKeys','refresh','defaultExpandAll','expandOnClickNode','showCheckbox','indent'],

    data() {
        return {
            visibleDeptSelect : false,
            nodeData: []
        }
    },

    methods: {
        checkChange(data, checked, indeter) {
            if(checked) {
                if(this.isSingle) {
                    this.nodeData = [];
                }                
                this.nodeData.push(data);
            }else {
                this.nodeData.forEach((n, index) => {
                    if(data.deptid === n.deptid) {
                        this.nodeData.splice(index, 1);
                    }
                })
            }
        },

        refresNodeData(){ 
            this.nodeData = [];
        },

        cancel(){
            this.visibleDeptSelect = false;
        },

        submit() {
            this.$emit('select-dept-node', this.nodeData);
            this.visibleDeptSelect = false;
        },

        openDialog() {
            this.visibleDeptSelect = true;
        }

    },

    mounted() { 
    },




}

</script>

<style scoped>

</style>
